package com.zyy.java8.samples.lambda;

import java.util.HashMap;
import java.util.function.BiConsumer;

/**
 * @author zhangyiying
 * @ClassName: Lambda5
 * @Description: Pre-Defined Functional Interfaces
 * @date 2021/12/27 11:40
 */
public class Lambda5 {

    public static void main(String[] args) {

        //BiConsumer Example
        BiConsumer<String, Integer> printKeyAndValue = (key, value) -> System.out.println(key + "-" + value);
        printKeyAndValue.accept("One", 1);
        printKeyAndValue.accept("Two", 2);

        System.out.println("##################");

        //Java Hash-Map foreach supports BiConsumer
        HashMap<String, Integer> dummyValues = new HashMap<>();
        dummyValues.put("One",1);
        dummyValues.put("Two",2);
        dummyValues.put("Three",3);

        dummyValues.forEach((key,value) -> System.out.println(key+"-"+value));
    }
}
